﻿using Rainbow.model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Rainbow.view
{
    /// <summary>
    /// EditFileNameDlg.xaml 的交互逻辑
    /// </summary>
    public partial class EditFileNameDlg : Window
    {
        public EditFileNameDlgViewModel windowViewModel;

        public EditFileNameDlg()
        {
            InitializeComponent();

            this.btnClose.Click += new RoutedEventHandler(Close_Click);
            this.btnOK.Click += new RoutedEventHandler(OK_Click);

            windowViewModel = new EditFileNameDlgViewModel();
            this.DataContext = windowViewModel;
            this.tbFileName.Focus();
        }

        private void OK_Click(object sender, RoutedEventArgs e)
        {
            bool chkFlag = Check();
            if (!chkFlag) return;

            this.DialogResult = true;
        }

        private void Close_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        private bool Check()
        {
            bool hasError = (Validation.GetHasError(tbFileName));

            return !hasError;
        }
    }

    public class EditFileNameDlgViewModel : ViewModelBase
    {
        public EditFileNameDlgViewModel()
        {

        }

        private string m_fileName;
        public string fileName
        {
            get { return m_fileName; }
            set
            {
                m_fileName = value;
                NotifyPropertyChanged();
            }
        }
    }
}
